package com.leemz.ch2.jdbc.inter.impl;

import com.leemz.ch2.jdbc.entity.Student;
import com.leemz.ch2.jdbc.inter.IRowMapper;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class StudentRowMapper implements IRowMapper<List<Student>> {
    @Override
    public List handleResult(ResultSet resultSet) throws Exception {
        List<Student> list = new ArrayList<>();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");
            Student student = new Student(name, age);
            student.setId(id);
            list.add(student);
        }
        return list;
    }
}
